<?php
class User_Model_Classes extends Pldkp_Db_Table_Abstract {
    protected $_name = 'classes';
    protected $_dependentTables = array('User_Model_Characters','User_Model_ClassesRoles');


    /*Returns an array with all containing all the classes*/
    public static function getClasses()
    {
        $table = new User_Model_Classes();
        $select = $table->select();
        $select->from($table,array('id','name'));
        $rows = $table->fetchAll($select);
        
        foreach ($rows as $class){
            $result[$class->id] = $class->name;
        }
        
        return $result;
    }
    
    public static function getById($id)
    {
        // id must be numeric
        if (!is_numeric($id)) {
            return null;
        }
        
        
        // Create static self
        $table = new self();
        
        // Create a select for getting the entry
        $select = $table->select()->where('id = ?', $id);
        $row = $table->fetchRow($select);
        
        // Return the row or null
        if ($row) {
            return $row;
        } else {
            return null;
        }
    }

}
?>